package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author sheng
 * @Date 2025/8/23 16:40
 */
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    /**
     * 新增分类
     * @param categoryDto
     */
    @PostMapping()
    @ApiOperation("新增分类")
    public Result addCategory(@RequestBody CategoryDTO categoryDto){
        categoryService.save(categoryDto);
        return Result.success();
    }

    /**
     * 分页查询
     * @param
     */
//    @GetMapping("/page")
//    @ApiOperation("分页查询")
//    public Result<PageResult> findByPage(@RequestBody CategoryPageQueryDTO dto){
//        PageResult pageResult = categoryService.getByPage(dto);
//
//        return Result.success(pageResult);
//    }
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分页查询：{}", categoryPageQueryDTO);
        PageResult pageResult = categoryService.getByPage(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
}
